import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:flutterlib/common/config/config.dart';
import 'package:flutterlib/common/style/font_awesome4_icons.dart';
import 'package:flutterlib/common/style/meterial_design_icons.dart';
import 'package:flutterlib/common/style/quhui_style.dart';
import 'package:flutterlib/common/utils/navigator_utils.dart';
import 'package:flutterlib/model/post/post_bean.dart';
import 'package:flutterlib/widgets/bussiness/post/base_post_list_item.dart';
import 'package:flutterlib/widgets/bussiness/user_info_widget.dart';
import 'package:like_button/like_button.dart';

class PostListItem extends BasePostListItem {
  final PostBean postBean;

  final VoidCallback onPressed;
  final LikeButtonTapCallback onZhanPressed;
  final VoidCallback onCommentPressed;
  final VoidCallback onCollectPressed;
  final AnimationController animationController;
  final Animation<dynamic> animation;

  PostListItem(this.postBean,
      {this.onPressed,
      this.animationController,
      this.animation,
      this.onZhanPressed,
      this.onCommentPressed,
      this.onCollectPressed})
      : super(postBean, onPressed: onPressed);

  @override
  Widget build(BuildContext context) {
    if (postBean != null && (postBean.thumbnail ?? '').isNotEmpty) {
      return normalItem(context);
    } else {
      return simpleItem(context);
    }
  }


  @override
  buildOperation() {
    return Row(
      children: <Widget>[
        LikeButton(
          isLiked: postBean.isLiked,
          onTap: onZhanPressed,
          size: 40,
          circleColor: CircleColor(
              start: Color(0xff00ddff),
              end: Color(0xff0099cc)),
          bubblesColor: BubblesColor(
            dotPrimaryColor: Color(0xff33b5e5),
            dotSecondaryColor: Color(0xff0099cc),
          ),
          likeBuilder: (bool isLiked) {
            return Icon(
              MIcon.thumb_up,
              color: isLiked
                  ? Colors.red
                  : Colors.grey,
            );
          },
          likeCount: postBean.likes,
          countBuilder: (int count, bool isLiked,
              String text) {
            Widget result;
            if (count == 0) {
              result = Text(
                "0",
                style: QuhuiConstant.minSubText,
              );
            } else
              result = Text(
                text,
                style: QuhuiConstant.minSubText,
              );
            return result;
          },
        ),
        InkWell(
          onTap: onCommentPressed,
          child: Container(
            width: 40,
            height: 40,
            alignment: Alignment.center,
            child: Icon(
              MIcon.textsms,
            ),
          ),
        ),
        Text(
          '${postBean.commentCount ?? 0}',
          style: QuhuiConstant.minSubText,
        ),
        InkWell(
          onTap: onCollectPressed,
          child: Container(
            width: 40,
            height: 40,
            alignment: Alignment.center,
            child: postBean.isCollect
                ? Icon(
              Icons.star,
              color:
              QuhuiColors.textColorRed,
            )
                : Icon(
              AIcon.star_empty,
            ),
          ),
        ),

        Padding(
          padding: const EdgeInsets.fromLTRB(8, 8, 0, 8),
          child: Text(
            (postBean.distance == null || postBean.distance == 0)
                ? "距离未知"
                : "${postBean.distance~/1000}km",
            style: QuhuiConstant.smallTextBold,
          ),
        )
      ],
    );
  }


}
